/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package xmarti.vacaxm.action;
    
import java.util.List;
import java.util.Set;
import xmarti.vacaxm.beans.sequence.*;
import xmarti.vacaxm.exception.ExceptionHibernateVacaxm;
import xmarti.vacaxm.model.ModelSequence;


public class ImplSequence {
    private ModelSequence model;
    public ImplSequence(){
        this.model=new ModelSequence(); 
    }
    public SequenceType getById(int id) throws ExceptionHibernateVacaxm{
        return this.model.getById(id);
    }
    public List<State> getStates() throws ExceptionHibernateVacaxm{
        return model.getListState();
    }
    
    public List<StateDefault> getStatesDefault(SequenceType sequenceType) throws ExceptionHibernateVacaxm{
        return model.getListStateDefault(sequenceType);
    }
    public List<SequenceType> getSequencesType() throws ExceptionHibernateVacaxm{
        return model.getListSequencesType();
    }
    
    public boolean update (Object object) throws ExceptionHibernateVacaxm{       
        return model.update(object);
    }
    public boolean update (Object object1,Object object2) throws ExceptionHibernateVacaxm{       
        return model.update(object1, object2);
    }
    
    public boolean add (Object object) throws ExceptionHibernateVacaxm{       
        return model.add(object);
    }
     public int add (State object) throws ExceptionHibernateVacaxm{       
        return model.add(object);
    }

    public void remove(Object object) throws ExceptionHibernateVacaxm{
        this.model.delete(object);
    }
    public int getMaxOrder(SequenceType sequenceType){
        int i=0 ;
        for(StateDefault s:sequenceType.getStates()){
            if (i< s.getOrder()) i=s.getOrder();
        }
        return i;
    }
    public int getMaxIdStateDefault(SequenceType sequenceType){
        return model.maxIdStateDefault(sequenceType);
    }
    public int deleteStateDefault(StateDefault stateDefault){
        return model.deleteStateDefault(stateDefault); 
    }
    public boolean delete(Object object) throws ExceptionHibernateVacaxm{
        return model.delete(object);
    }
    public SequenceType getSequenceTypeByName(String name){
        SequenceType sequenceType = model.getSequenceTypeByName(name);
        if (sequenceType==null) sequenceType=new SequenceType(); 
        return sequenceType; 
    }
    
}
